package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.ListDealHandler;
import com.cungmua.app.model.request.SearchDealRequest;
import com.cungmua.app.model.response.ListDealResponse;
import com.cungmua.app.net.CungMuaAPI;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 6/24/14.
 */
public class SearchDealTask extends AuthenticatedTask<SearchDealRequest, Void, ListDealResponse> {
    private Context context;
    private ListDealHandler handler;

    public SearchDealTask(Context context, ListDealHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected ListDealResponse doInBackground() throws RetrofitError {
        SearchDealRequest request = params[0];
        return CungMuaAPI.getService().searchDeal(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(ListDealResponse listDealResponse) {
        handler.onListDealReceived(listDealResponse);
    }
}

